<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
	</head>

	<body>
		<script type="text/javascript" src="js/jquery3.3.1.js"></script>
		<script type="text/javascript">
			console.log($().version);
			console.log('a');
			/*
			 * 不方便控制prototype属性，不利于高效扩展对象方法，
			 * instanceof操作符失效且constructor属性丢失
			 */
			/*function Person(name){
				return {
					name: name,
					getName:function(){
						return name;
					}
				}
			}
			console.log(Person('hello').getName());*/

			/*
			 *  //编码相对较为复杂，需要_Person作为辅助的内部构造函数，
			 *  //且需要手动修改prototype和constructor等属性
			 * function Person(name){
				//lazy loading 
				if(!Person.inited){
					Person._Person = function(name){
						this.name = name;
					};
					Person._Person.prototype = {
						constructor :Person,
						getName : function(){
							return this.name;
						}
					};
					
					Person.prototype = Person._Person;
					Person.inited = true;
				}
				return new Person._Person(name);
			}
			console.log(Person('second').getName());*/

			/*
			 * 在判断this instanceof Person时需要指明构造函数名称Person，
			 * 抽象程度不够高，修改构造函数名称时需要手动修改该语句
			 */
			/*function Person(name){
				if(!(this instanceof Person)){
					return new Person(name);
				}
				
				this.name = name;
			}
			Person.prototype.getName = function(){
				return this.name;
			}
			console.log(Person('third').getName());*/

			/*function Person(name) {
				// arguments.callee指向Person函数
				// this.constructor仅在使用了new的情形下指向Person函数
				if(arguments.callee !== this.constructor) {
					return new arguments.callee(name);
				}
				this.name = name;
			}
			Person.prototype.getName = function() {
				return this.name;
			};
			console.log(new Person('Ralph').getName()); //Ralph
			console.log(Person('Ralph').getName()); //Ralph*/
		</script>
	</body>

</html>